﻿#ifndef COMMAND_H
#define COMMAND_H
#include <QString>
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
//传输认证


const static QByteArray VERSION = "CHUNSOURCE_FORWARD_1.0"; //传输协议标志
const static QByteArray ERRORSTREAM = "CHUNSOURCE_FORWARD_ERRORSTREAM"; //错误流标志

//控制命令
const static QByteArray NEWPORT = "NEWPORT";      //开放端口
const static QByteArray CLOSEPORT = "CLOSEPORT";    //关闭端口
const static QByteArray CHECKEXIST = "CHECKEXIST";    //校验当前端口
const static QByteArray ISOCCUPY = "ISOCCUPY";      //端口被占用
const static QByteArray ERRORDATA = "ERRORDATA";      //数据不正确
const static QByteArray PORTOPEN = "PORTOPEN";      //端口已开启
const static QByteArray ADDSERVICE = "ADDSERVICE";  //增加服务的反向连接的数量


enum CONNECT_STATUS{DONE,SUCCESS,FAILED,WAIT};



class CommandTools
{
public:
    static bool StirngTojson(const QByteArray json,QJsonObject& object)
    {
        try{
            QJsonParseError error;
            QJsonDocument document = QJsonDocument::fromJson(json,&error);
            if(error.error!=QJsonParseError::NoError)
            {
                return false;
            }
            object = document.object();
            return true;
        }catch(...)
        {
            return false;
        }
        
    }
};
#endif // COMMAND_H
